package com.eims.sls_app.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.MySingleton;
import com.android.volley.toolbox.RequestParams;
import bls.juejin.cn.R;
import com.eims.sls_app.dataaccess.Show_JC_Details;
import com.eims.sls_app.protocol.MD5;
import com.eims.sls_app.protocol.RspBodyBaseBean;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 数据请求类 功能：封装所有数据请求，一个方法提交一类请求 Created by lian on 2015/3/30.
 */
public abstract class RequestUtil {
	private Dialog dialog;
	private Context context;
	private Request jsonObjectRequest;
	public static final boolean DEBUG = true;
	private static final String TAG = "RequestUtil";
	private boolean isShowDialog = false;// 是否弹窗
	private boolean isShouldCache = false;// 是否设置缓存
	private long cacheTime;// 缓存时间

	// private String dialogTitle;// 弹窗提示

	/**
	 * @param context
	 *            上下文
	 * @param isShouldCache
	 *            是否设置缓存
	 * @param cacheTime
	 *            缓存时间
	 */
	public RequestUtil(Context context, boolean isShouldCache, long cacheTime) {
		this.context = context;
		this.isShouldCache = isShouldCache;
		this.cacheTime = cacheTime;
	}

	/**
	 * 带弹窗的请求类构造器
	 * 
	 * @param context
	 *            上下文
	 * @param isShouldCache
	 *            是否设置缓存
	 * @param cacheTime
	 *            缓存时间
	 * @param isCancelDialog
	 *            是否可取消弹窗 true为可取消，false则不可取消
	 * @param dialogTitle
	 *            弹窗提示
	 */
	public RequestUtil(Context context, boolean isShouldCache, long cacheTime,
			boolean isCancelDialog, String dialogTitle) {
		this.context = context;
		dialog = createLoadingDialog(context, dialogTitle, isCancelDialog);
		isShowDialog = true;
		this.isShouldCache = isShouldCache;
		this.cacheTime = cacheTime;
	}

	/******************************** MainActivity ************************************************/

	/**
	 * 检查app更新
	 */
	public void checkUpdateApp() {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "{\"identify\":\"android\",\"appversion\":\""
				+ AppTools.getVerName(context) + "\"}";
		if (DEBUG)
			Log.i(TAG, "检查app更新====   " + info);
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "0";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 下载图片
	 */
	public void DownloadImagview() {

		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "";
		if (DEBUG)
			Log.i(TAG, "检查app更新====   " + info);
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "73";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 获取最近一条中奖信息
	 */
	public void getCurrentWinInfo(String uid) {
		String key = MD5.md5(App.MD5_key);
		String info = "{\"uid\":\"" + uid + "\"}";
		if (DEBUG)
			Log.i(TAG, "获取最近一条中奖信息====   " + info);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, uid);
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, uid);
		String opt = "61";
		Log.i(TAG, "获取最近一条中奖信息"+RequestParams.convertParams(context, opt, info));
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 获取中奖详情
	 */
	public void getWinDetail() {
		String key = MD5.md5(App.MD5_key);
		String info = RspBodyBaseBean.changeMyLotteryInfo_Info(
				App.lotteryIds + ",72,73", 1, 2, 5, 3, 3);
		if (DEBUG)
			Log.i(TAG, "获取中奖详情====   " + info);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "18";
		Log.i(TAG, "获取中奖详情"+RequestParams.convertParams(context, opt, info));
		
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 获取合买比列和认购比例
	 */
	public void getBuyParams() {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "";
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "53";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 获取站点名称和客服电话
	 */
	public void getSiteNameAndPhone() {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "";
		if (DEBUG)
			Log.i(TAG, "获取站点名称和客服电话====   " + info);
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "63";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 
	 * 获取41号接口初始化信息
	 */

	public void getInitParams41() {

		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "";
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "41";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);

	}

	/**
	 * 获取71号接口初始化数据
	 * 
	 */

	public void getRechargeParams71() {

		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = "";
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "71";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/******************************** 购彩大厅 ************************************************/

	/**
	 * 获取购彩大厅所有数据（竞彩数据除外） opt="10"
	 * 
	 * @param lottryids
	 *            彩种id
	 */
	public void getLotteryData(String lottryids) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = RspBodyBaseBean.changeLottery_info(lottryids);
		if (DEBUG)
			Log.i(TAG, "获取购彩大厅所有数据====   " + info);
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "10";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}
	
	
	public void getCircleData(String datatime) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = datatime;
		
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "86";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 自动登录 opt = "2"
	 */
	public void doAutoLogin() {
		SharedPreferences settings = context
				.getSharedPreferences("app_user", 0);
		boolean isLogin = false;
		String name = "";
		String pass = "";
		if (settings.contains("isLogin")) {
			isLogin = settings.getBoolean("isLogin", false);
		}
		if (settings.contains("name")) {
			name = settings.getString("name", null);
		}
		// 判断是否有存 用户名
		if (isLogin) {
			// 判断是否有存 密码
			if (settings.contains("pass")) {
				pass = settings.getString("pass", null);
			}
		}
		if (null != pass && null != name && !"".equals(name)
				&& !"".equals(pass) && name.length() != 0 && pass.length() != 0) {
			// 对密码进行MD5加密
			String pass2 = MD5.md5(pass + App.MD5_key);
			String time = RspBodyBaseBean.getTime();
			String imei = RspBodyBaseBean.getIMEI(context);
			String opt = "2";
			String info = RspBodyBaseBean.changeLogin_Info(name, pass2);
			String auth = RspBodyBaseBean.changeLogin_Auth(
					RspBodyBaseBean.getCrc(time, imei,
							MD5.md5(App.MD5_key), info, "-1"), time, imei);
			String[] values = { opt, auth, info };
			if (DEBUG)
				Log.i(TAG, "自动登录====   " + info);
			commonSet(App.names, values);
		}
	}

	/**
	 * 获取竞彩对阵信息 opt = "10"
	 * 
	 * @param jcLottryid
	 *            竞彩彩种id 72:足球 73：篮球
	 */
	public void getJCData(String jcLottryid) {
		String key = MD5.md5(App.MD5_key);
		String info = RspBodyBaseBean.changeLottery_info(jcLottryid, "-1");
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "10";
		String[] values = { opt, auth, info };
		if (DEBUG)
			Log.i(TAG, " 获取竞彩对阵信息----" + RequestParams.convertParams(context, opt, info));
		commonSet(App.names, values);
	}

	/**
	 * 请求广播消息
	 */
	public void getWinMessage() {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String info = "{\"lotteryIds\":\"" + App.lotteryIds + "\"}";
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "51";
		String[] values = { opt, auth, info }; // 请求广播消息，opt=“51” info ="5,6,7"
		if (DEBUG)
			Log.i(TAG, "请求广播消息的info   " + info);
		commonSet(App.names, values);
	}

	/**
	 * 提交认购投注请求
	 * 
	 * @param totalCount
	 * @param totalMoney
	 * @param isStopChase
	 */
	public void commitBetting(long totalCount, long totalMoney, int isStopChase) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String lottryId = App.lottery.getLotteryID();
		String info;
		AppTools.addlottery();
		Set set = App.allLotteryName.keySet();
		Iterator it = set.iterator();
		String lottryName = "";
		while (it.hasNext()) {
			String name = (String) it.next();
			// Log.i(TAG,"IT.NEXT----"+name);
			String id = App.allLotteryName.get(name);
			// Log.i(TAG,"id----"+id);
			if (id.equals(lottryId)) {
				lottryName = name;
				break;
			}
		}
		if ("73".equals(lottryId)) {// 竞彩篮球
			info = RspBodyBaseBean.changeBet_info(lottryId, "-1", App.bei,
					1, 1, 0, 0, "", "", 0, (totalCount * 2 * App.bei),
					totalCount, 0, 0, App.ball, App.lottery.getType()
							+ "");
		} else if ("28".equals(lottryId)) {// 时时彩
			info = RspBodyBaseBean.changeBet_info_ssc("28", App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);
		} else if ("72".equals(lottryId)) { // 竞彩足球 此处修改期号为"-1";

			/*info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);*/
			info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 2,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);

		} else {
			// TODO
			// Log.i("App.list_numbers",
			// App.list_numbers.get(0).getNumber());
			info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);
			// Log.i("App.list_numbers",
			// App.list_numbers.get(0).getNumber());
			Log.i(TAG, "" + info);
		}
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "11";
		String[] values = { opt, auth, info }; // 请求广播消息，opt=“51” info ="5,6,7"
		Log.e(TAG, lottryName + "提交投注请求info   " + info);
		if (DEBUG)
			Log.i(TAG, lottryName + "提交投注请求info   " + RequestParams.convertParams(context, opt, info));
		commonSet(App.names, values);
	}
	/**
	 * 提交认购投注请求
	 * 
	 * @param totalCount
	 * @param totalMoney
	 * @param isStopChase
	 */
	/**
	 * 提交认购投注请求
	 * 
	 * @param totalCount
	 * @param totalMoney
	 * @param isStopChase
	 */
	public void commitBetting(long totalCount, long totalMoney, int isStopChase,int secrecyLevel) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String lottryId = App.lottery.getLotteryID();
		String info;
		AppTools.addlottery();
		Set set = App.allLotteryName.keySet();
		Iterator it = set.iterator();
		String lottryName = "";
		while (it.hasNext()) {
			String name = (String) it.next();
			// Log.i(TAG,"IT.NEXT----"+name);
			String id = App.allLotteryName.get(name);
			// Log.i(TAG,"id----"+id);
			if (id.equals(lottryId)) {
				lottryName = name;
				break;
			}
		}
		if ("73".equals(lottryId)) {// 竞彩篮球
			info = RspBodyBaseBean.changeBet_info(lottryId, "-1", App.bei,
					1, 1, 0, 0, "", "", secrecyLevel, (totalCount * 2 * App.bei),
					totalCount, 0, 0, App.ball, App.lottery.getType()
							+ "");
		} else if ("28".equals(lottryId)) {// 时时彩
			info = RspBodyBaseBean.changeBet_info_ssc("28", App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);
		} else if ("72".equals(lottryId)) { // 竞彩足球 此处修改期号为"-1";

			/*info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);*/
			info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 2,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);

		} else {
			// TODO
			// Log.i("App.list_numbers",
			// App.list_numbers.get(0).getNumber());
			info = RspBodyBaseBean.changeBet_info2(lottryId, App.lottery
					.getIsuseId(), App.bei, 1, 1, 0, 0, "", "", 0,
					totalMoney / App.qi, totalCount,
					App.qi > 1 ? App.qi : 0, App.qi == 1 ? 0
							: totalMoney, App.list_numbers, isStopChase);
			// Log.i("App.list_numbers",
			// App.list_numbers.get(0).getNumber());
			Log.i(TAG, "" + info);
		}
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "11";
		String[] values = { opt, auth, info }; // 请求广播消息，opt=“51” info ="5,6,7"
		Log.e(TAG, lottryName + "提交投注请求info   " + info);
		if (DEBUG)
			Log.i(TAG, lottryName + "提交投注请求info   " + RequestParams.convertParams(context, opt, info));
		commonSet(App.names, values);
	}
	/**
	 * 提交认购投注请求
	 * 
	 * @param -totalCount
	 * @param totalMoney
	 * @param isStopChase
	 */
	public void commitBetting_jc_voptimization(long totalMoney,
			int isStopChase, List<Show_JC_Details> list_Show, int youhua_type,
			String title, String SchemeContent, int baoCount, int allCount,
			int count, int secrecyLevel, int Bonus) {

		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String lottryId = App.lottery.getLotteryID();
		String info = "";
		AppTools.addlottery();
		Set set = App.allLotteryName.keySet();
		Iterator it = set.iterator();
		String lottryName = "";
		while (it.hasNext()) {
			String name = (String) it.next();
			Log.i(TAG, "IT.NEXT----" + name);
			String id = App.allLotteryName.get(name);
			Log.i(TAG, "id----" + id);
			if (id.equals(lottryId)) {
				lottryName = name;
				break;
			}
		}
		if ("73".equals(lottryId)) {// 竞彩篮球
			info = RspBodyBaseBean.changeBet_info2_jclq_voptimization(lottryId,
					App.bei, allCount, count, 0, title, SchemeContent,
					secrecyLevel, App.qi > 1 ? App.qi : 0,
					App.qi == 1 ? 0 : totalMoney, App.ball,
					isStopChase, list_Show, youhua_type, baoCount, Bonus); // 最后的0优化类别
//		} else if ("72".equals(lottryId)) {
		} else {
			info = RspBodyBaseBean.changeBet_info2_jc_voptimization(lottryId,
					App.bei, allCount, count, 0, title, SchemeContent,
					secrecyLevel, App.qi > 1 ? App.qi : 0,
					App.qi == 1 ? 0 : totalMoney, App.list_numbers,
					isStopChase, list_Show, youhua_type, baoCount, Bonus); // 最后的0优化类别
		}
		System.out.println("info===" + info);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "72";
		Log.i(TAG, "提交奖金优化请求"+RequestParams.convertParams(context, opt, info));
		String[] values = { opt, auth, info };
		
		
		
		if (DEBUG)
			Log.i(TAG, lottryName + "提交投注请求－－－info   " + info);
		commonSet(App.names, values);
	}

	/**
	 * 获取竞彩任选9和胜负彩对阵 opt = "10"
	 * 
	 * @param jcLottryid
	 *            竞彩彩种id 74:胜负彩 75:任选9
	 */
	public void getRx9AndSfcData(String jcLottryid) {
		String key = MD5.md5(App.MD5_key);
		String info = RspBodyBaseBean.changeLottery_infoAgainst(jcLottryid);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
		String auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
		String opt = "10";
		String[] values = { opt, auth, info };
		if (DEBUG)
			Log.i(TAG, " 获取竞彩任选9和胜负彩对阵信息----" + info);
		commonSet(App.names, values);
	}

	/**
	 * 提交合买投注请求
	 * 
	 * @param totalMoney
	 *            总金额
	 * @param shareMoney
	 *            每份金额
	 * @param count
	 *            购买的份数
	 * @param baoCount
	 *            保底份数
	 * @param Bonus
	 *            佣金
	 * @param title
	 *            方案名称
	 * @param content
	 *            方案内容
	 * @param secrecyLevel
	 *            保密设置
	 * @param flag
	 *            是否追号。
	 */
	public void commitFollow(int totalMoney, double shareMoney, long count,
			int baoCount, int Bonus, String title, String content,
			int secrecyLevel, boolean flag) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String lottryId = App.lottery.getLotteryID();
		String info;
		AppTools.addlottery();
		Set set = App.allLotteryName.keySet();
		Iterator it = set.iterator();
		String lottryName = "";
		while (it.hasNext()) {
			String name = (String) it.next();
			Log.i(TAG, "IT.NEXT----" + name);
			String id = App.allLotteryName.get(name);
			Log.i(TAG, "id----" + id);
			if (id.equals(lottryId)) {
				lottryName = name;
				break;
			}
		}
		if ("73".equals(App.lottery.getLotteryID())) {

			info = RspBodyBaseBean.changeBet_info(
					App.lottery.getLotteryID(), "-1", App.bei,
					(int) (totalMoney / shareMoney), count, baoCount, Bonus,
					title, content, secrecyLevel, totalMoney, totalMoney
							/ (2 * App.bei), 0, 0, App.ball,
					App.lottery.getType() + "");

		} else if ("72".equals(App.lottery.getLotteryID())) {
			info = RspBodyBaseBean.changeBet_info_jczq(
					App.lottery.getLotteryID(), "-1", App.bei,
					(int) (totalMoney / shareMoney), count, baoCount, Bonus,
					title, content, secrecyLevel, totalMoney, totalMoney
							/ (2 * App.bei), 0, 0, App.list_numbers,
					App.lottery.getType() + "");

		} else {
			if (flag) { // 大乐透追加玩法发起合买的时候
				info = RspBodyBaseBean.changeBet_info2(
						App.lottery.getLotteryID(),
						App.lottery.getIsuseId(), App.bei,
						(int) (totalMoney / shareMoney), (int) count, baoCount,
						Bonus, title, content, secrecyLevel, totalMoney,
						totalMoney / (3 * App.bei), 0, 0,
						App.list_numbers, 0);
			} else {
				info = RspBodyBaseBean.changeBet_info2(
						App.lottery.getLotteryID(),
						App.lottery.getIsuseId(), App.bei,
						(int) (totalMoney / shareMoney), (int) count, baoCount,
						Bonus, title, content, secrecyLevel, totalMoney,
						totalMoney / (2 * App.bei), 0, 0,
						App.list_numbers, 0);
				if ("28".equals(App.lottery.getLotteryID())) {// 时时彩
					info = RspBodyBaseBean.changeBet_info_ssc(
							App.lottery.getLotteryID(),
							App.lottery.getIsuseId(), App.bei,
							(int) (totalMoney / shareMoney), (int) count,
							baoCount, Bonus, title, content, secrecyLevel,
							totalMoney, totalMoney / (2 * App.bei), 0, 0,
							App.list_numbers, 0);
				}
			}
		}
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "11";
		String[] values = { opt, auth, info };
		if (DEBUG)
			Log.i(TAG, lottryName + "提交合买投注请求info   " + info);
		commonSet(App.names, values);
	}

	/******************************** 购彩大厅 ************************************************/

	/**
	 * 加入合买 opt="12"
	 * 
	 * @param schemesId
	 *            方案id
	 * @param buyShare
	 *            购买份数
	 * @param shareMoney
	 *            购买金额
	 */
	public void joinFollow(String schemesId, int buyShare, long shareMoney) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String info = RspBodyBaseBean.changeFollow_info(schemesId, buyShare,
				shareMoney);
		if (DEBUG)
			Log.i(TAG, "加入合买====   " + info);
		String imei = RspBodyBaseBean.getIMEI(context);
		String crc = RspBodyBaseBean.getCrc(time, imei, App.key, info,
				App.user.getUid());
		// String crc = RspBodyBaseBean.getCrc(time, imei,
		// MD5.md5(App.user.getUserPass() + App.MD5_key), info,
		// App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "12";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/******************************** 个人中心 ************************************************/

	/**
	 * 获取积分参数 opt 65
	 */
	public void getIntegralParams() {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String info = "";
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "65";
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 兑换积分 opt 26
	 */
	public void exchangeIntegral(double score) {
		String key = MD5.md5(App.MD5_key);
		String time = RspBodyBaseBean.getTime();
		String imei = RspBodyBaseBean.getIMEI(context);
		String info = "{\"score\":\"" + score + "\"}";
		String crc = RspBodyBaseBean.getCrc(time, imei, key, info,
				App.user.getUid());
		String auth = RspBodyBaseBean.getAuth(crc, time, imei,
				App.user.getUid());
		String opt = "26";
		if (DEBUG)
			Log.i(TAG, "兑换积分====   " + info);
		String[] values = { opt, auth, info };
		commonSet(App.names, values);
	}

	/**
	 * 通用设置
	 * 
	 * @param names
	 *            请求参数名
	 * @param values
	 *            请求参数值
	 */
	public void commonSet(String[] names, String[] values) {
		Map<String, String> params = new HashMap<String, String>();
		for (int i = 0; i < names.length; i++) {
			params.put(names[i], values[i]);
		}
		MySingleton mySingleton = MySingleton.getInstance(context);

		Log.i(TAG, "params"+params);
		jsonObjectRequest = new JsonObjectRequest(App.path, params,
				new Response.Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						if (null != dialog && dialog.isShowing())
							dialog.dismiss();
						responseCallback(response);
						if (DEBUG)
							Log.i(TAG,"getHttpRes==>response"+ response.toString());
					}
				}, new Response.ErrorListener() {
					@Override
					public void onErrorResponse(VolleyError error) {
						if (null != dialog && dialog.isShowing())
							dialog.dismiss();
						RequestParams.convertError(context, error, true);
						responseError(error);
						if (DEBUG) {
							String className = error.getClass().getName();
							Log.e(TAG, "className" + className);
							Log.e(TAG,
									"getHttpRes==>onErrorResponse()"
											+ error.getMessage());
						}
					}
				});
		jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0,
				1.0f));
		jsonObjectRequest.setShouldCache(isShouldCache);// 是否设置缓存
		jsonObjectRequest.setCacheTime(cacheTime);// 设置缓存时间
		mySingleton.addToRequestQueue(jsonObjectRequest);
		if (isShowDialog) {
			dialog.show();
			dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
				@Override
				public void onCancel(DialogInterface dialog) {
					jsonObjectRequest.cancel();// 取消请求
				}
			});
		}
	}

	/**
	 * 得到自定义的progressDialog
	 * 
	 * @param context
	 * @param msg
	 * @return
	 */
	public static Dialog createLoadingDialog(Context context, String msg,
			boolean iscancel) {

		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.layout_progressbar, null);// 得到加载view
		LinearLayout layout = (LinearLayout) v
				.findViewById(R.id.layout_progress_horizontal);// 加载布局
		// main.xml中的ImageView
		ImageView spaceshipImage = (ImageView) v.findViewById(R.id.iv_progress);
		TextView tipTextView = (TextView) v.findViewById(R.id.tv_progress);// 提示文字
		// 加载动画
		Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
				context, R.anim.progress_animation);
		// 使用ImageView显示动画
		spaceshipImage.startAnimation(hyperspaceJumpAnimation);
		tipTextView.setText(msg);// 设置加载信息

		Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog
		loadingDialog.setCanceledOnTouchOutside(false);
		loadingDialog.setCancelable(iscancel);// 不可以用“返回键”取消
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
		return loadingDialog;

	}

	/**
	 * 获取当前请求对象
	 * 
	 * @return jsonObjectRequest请求对象
	 */
	public Request getRequest() {
		return jsonObjectRequest;
	}

	/**
	 * JsonObjectRequest回调方法
	 * 
	 * @param reponseJson
	 *            回调json对象
	 */
	public abstract void responseCallback(JSONObject reponseJson);

	/**
	 * JsonObjectRequest错误回调方法
	 * 
	 * @param error
	 *            VolleyError对象
	 */
	public abstract void responseError(VolleyError error);

}
